<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.util.*" %>
<%@ page import="com.ionglobal.db.*" %>
<%@ page import="com.ionglobal.lib.*" %>
<%@ page import="com.ionglobal.misc.*" %>

<%@ include file="../init_include.jsp" %>

<%
	Integer catId;
	int totalpages,pageid=0;
	int pagerows=Page.getPageRows();
	int totalrows=0;
    String ordermode="desc";
    String orderfield="id";
    String whereClause="";
  
	Sysop sysop=(Sysop)session.getAttribute("sysop");	
	int departid = sysop.getDepartid();
	try {
		if (request.getParameter("id")!=null)
			departid=Integer.parseInt(request.getParameter("id"));
	}	catch(NumberFormatException e) {
		return ;
	}	

	if(request.getParameter("ordermode")!=null)
		ordermode=request.getParameter("ordermode");	
	if(request.getParameter("orderfield")!=null)
		orderfield=request.getParameter("orderfield");	
	
	
	try {
		if (request.getParameter("pageid")!=null)
			pageid=Integer.parseInt(request.getParameter("pageid"));
		else
			pageid=1;
	}	catch(NumberFormatException e) {
		out.println(e+"pageid");
		pageid=1;
	}	
	
	try {
		if (request.getParameter("pagerows")!=null)
			pagerows=Integer.parseInt(request.getParameter("pagerows"));
	} catch(NumberFormatException e) {
		out.println(e+"pagerows");
	}	

	if(request.getParameter("whereClause")!=null)
		whereClause=request.getParameter("whereClause");

	totalrows=DepartmentDB.getDepartmentNum(dbi,departid,whereClause);
	totalpages = (int)Math.ceil((double)totalrows/pagerows);
	if(pageid>totalpages)
		pageid=totalpages;
	if(pageid<=1)
		pageid=1;
%>	
<html>
<head>
<title><%=Language.getNameByCode("sys.depart.manage","Department Manage")%></title>
<meta http-equiv="Content-Type" content="text/html; charset=<%=Language.getHTMLLanguageStr()%>">
<link rel="stylesheet" href="../css.css" type="text/css">
<SCRIPT language=JavaScript1.2 src="../script/Ion_Show.js"></SCRIPT>
<script language="javascript">
<!--
	function Ion_Search()
	{
		add_Ion('vmsSelectFrame.jsp','../sys/sys_depart_search.jsp','curid','depart_search');
	}

	function Ion_SelectByAll()
	{
		location.href="select_department.jsp?id="+document.formIon.id.value;
	}

	function Ion_Select()
	{
		var str=selectOneIon('vmsSelectFrame.jsp','','<%=Language.getNameByCode("sys.depart","department")%>');
		if(str!=null) {
		 	var top=this;
			var intPos=str.indexOf("|");
			window.opener.formIon.departid.value=str.substring(0,intPos);
 			window.opener.formIon.departname.value=str.substring(intPos+1); 	
 			if (parent) top=parent;
			top.close(); 		
		}
	}
-->
</script>
</head>

<body bgColor=#d6d3ce leftMargin=0 
style="BORDER-BOTTOM: 0px outset; BORDER-LEFT: 0px outset; BORDER-RIGHT: 0px outset; BORDER-TOP: 0px outset" 
topMargin=0>
<FORM name="formIon" method="post" action="?">
	<table width="100%" border="0">
 		<tr>
			<td align="left">
				<%=Language.getNameByCode("sys.depart.list","Department List:")%><%=PageStr.getPageHead(totalrows,pageid,pagerows,totalpages)%>
			</td>
    	<td align=right>
    		<%=PageStr.PageForm(pageid,totalpages)%><input type="submit" name="Submit" value="go" style="width:0">
    	</td>
   	</tr>
	</table>
	<TABLE border=0 cellPadding=0 cellSpacing=1 height="100%" width="100%">
		<input type="hidden" name="catid" value="0">
		<input type="hidden" name="id" value="<%=departid%>">
		<input type="hidden" name="whereClause" value="<%=whereClause%>">
		<INPUT name="objid" type="hidden">
		<INPUT name="objtext" type="hidden">
		<INPUT name="actionurl" type="hidden">
		<input type="hidden" name="orderfield" value="<%=orderfield%>">
		<input type="hidden" name="ordermode" value="<%=ordermode%>">
  	<TR>
    <TD>

    <%
	/*
   DictApp da=new DictApp();
   Properties TypeP=da.getDictProperties(dbi,"ProjectType",1,0,"sName","asc");
   Properties StatusP=da.getDictProperties(dbi,"ProjectStatus",1,0,"sName","asc");
   */
    
   Table table=new Table();
   table.setSortMode(ordermode);
   table.setSortField(orderfield);
   table.setSelectionMode("multiple");

   table.addColumn("no","id",0,"center","left","number");
   table.addColumn(Language.getNameByCode("sys.depart.id","ID"),"id",30,"center","left","text");
   table.addColumn(Language.getNameByCode("sys.depart.name","Department Name"),"name",100,"center","left","text");
   table.addColumn(Language.getNameByCode("sys.depart.code","Department Code"),"code",60,"center","left","text");
   table.addColumn(Language.getNameByCode("sys.depart.phone","Telephone"),"phone",80,"center","left","text");
   table.addColumn(Language.getNameByCode("sys.depart.email","Email"),"email",200,"center","center","text");
   table.addColumn(Language.getNameByCode("sys.depart.leader","Leader"),"leader",80,"center","left","text");

    ArrayList rowsList=new ArrayList();
    try {
     Vector vc=DepartmentDB.getDepartment(dbi,departid,whereClause,pageid,pagerows,orderfield,ordermode);
     String rowData="";
     for(int i=0;i<vc.size();i++) {
      Department depart=(Department)vc.get(i);
      rowData=depart.getId()+"|"+depart.getId()+"|"+depart.getName()+"|"+depart.getCode()+"|"+(depart.getPhone()+" ")+"|"+depart.getEmail()+"|"+depart.getLeader();
      rowsList.add(rowData);
     }
    } catch(Exception E) {
    }

    ArrayList menuList=new ArrayList();
    TableMenu tm=null;
    tm=new TableMenu(Language.getNameByCode("sys.depart.Select","Select A Department"),"JavaScript:Ion_Select();",false);
    menuList.add(tm);
    tm=new TableMenu(Language.getNameByCode("sys.depart.Search","Search Department"),"javascript:Ion_Search();",true);
    menuList.add(tm);
    tm=new TableMenu(Language.getNameByCode("sys.depart.SeeChild","View Sub-Department"),"javascript:changeIon('','"+Language.getNameByCode("sys.depart","department")+"');",true);
    menuList.add(tm);    
    tm=new TableMenu(Language.getNameByCode("sys.depart.alldepartselect","Select Department Fron All"),"javascript:Ion_SelectByAll();",true);
    menuList.add(tm);
    tm=new TableMenu(Language.getNameByCode("sys.Head.Refresh","Refresh"),"javascript:self.location.reload();",false);
    menuList.add(tm);

    table.setTableMenu(menuList);
    table.setRowsList(rowsList);
    TableDB tdb=new TableDB();
    out.print(tdb.draw(table));
    %>

	</TD>
 	</TR>
</TABLE>
</FORM>
</body>
</html>
<%@ include file="../init_free.jsp" %>